package com.fsy.algorithm;

import java.math.BigDecimal;

/**
 * Created by shuangyufeng on 2017/5/5.
 */
public class Factorial {

    public static void main(String[] args){

        /*
        int 太小 只能计算很小的阶乘
         */
//        int num = getFactorial(15);

        BigDecimal num = getFactorial(new BigDecimal(100));
        System.out.println("num == " + num);
    }

    private static int getFactorial(int value){

        if(value <= 1){
            return 1;
        }else{
            return value * getFactorial(value - 1);
        }
    }

    private static BigDecimal getFactorial(BigDecimal value){
        if(value.compareTo(BigDecimal.ZERO) <= 0){
            return new BigDecimal(1);
        }else{
            return value.multiply(getFactorial(value.subtract(new BigDecimal("1"))));
        }
    }
}
